//
//  LRStatustabCell.swift
//  WeiboX
//
//  Created by admin on 05/12/2016.
//  Copyright © 2016 iOS_Objective-C. All rights reserved.
//

import UIKit
import SnapKit

let StatusItemMargin: CGFloat = 10

class LRStatusTableVCell: UITableViewCell {
	
	var toolBarTopConstraint: Constraint?
	
	var statusVM: LRStatusVM? {
		didSet {
			statusOriginalV.statusVM = statusVM
			statusToolBar.statusVM = statusVM
			
			
			statusRetweetV.statusVM = statusVM
			
			
			if statusVM?.status?.retweeted_status != nil {
				// 显示转发微博
				statusRetweetV.isHidden = false
				// 更新约束
				toolBarTopConstraint?.deactivate()
				statusToolBar.snp.makeConstraints({ (make) in
					toolBarTopConstraint = make.top.equalTo(statusRetweetV.snp.bottom).constraint
				})
			} else {
				// 隐藏转发微博
				statusRetweetV.isHidden = true
				// 更新约束
				toolBarTopConstraint?.deactivate()
				statusToolBar.snp.makeConstraints({ (make) in
					toolBarTopConstraint = make.top.equalTo(statusOriginalV.snp.bottom).constraint
				})
			}
		}
	}
	
	private lazy var statusOriginalV: LRStatusOriginalV = LRStatusOriginalV()
	private lazy var statusToolBar: LRStatusToolBarV = LRStatusToolBarV()
	private lazy var statusRetweetV: LRStatusRetweetV = LRStatusRetweetV()

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
	
	override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
		super.init(style: style, reuseIdentifier: reuseIdentifier)
		
		setupUI()
	}
	
	required init?(coder aDecoder: NSCoder) {
		fatalError("init(coder:) has not been implemented")
	}
	
	private func setupUI() {
		contentView.addSubview(statusOriginalV)
		contentView.addSubview(statusRetweetV)
		contentView.addSubview(statusToolBar)
		
		statusOriginalV.snp.makeConstraints { (make) in
			make.top.equalToSuperview().offset(8)
			make.leading.trailing.equalToSuperview()
		}
		
		statusRetweetV.snp.makeConstraints { (make) in
			make.top.equalTo(statusOriginalV.snp.bottom)
			make.leading.trailing.equalTo(statusOriginalV)
		}
		
		statusToolBar.snp.makeConstraints { (make) in
			toolBarTopConstraint = make.top.equalTo(statusOriginalV.snp.bottom).constraint
			make.height.equalTo(35)
			make.bottom.equalToSuperview()
			make.leading.equalToSuperview()
			make.width.equalToSuperview()
		}
	}

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
